import sqlite3
from typing import List, Dict, Any

def get_connection(db_path: str) -> sqlite3.Connection:
    """获取数据库连接，启用Row工厂"""
    conn = sqlite3.connect(db_path)
    conn.row_factory = sqlite3.Row
    return conn

def execute_query(conn: sqlite3.Connection, query: str, params: tuple = ()) -> List[Dict]:
    """执行查询语句，返回结果字典列表"""
    try:
        cursor = conn.cursor()
        cursor.execute(query, params)
        results = [dict(row) for row in cursor.fetchall()]
        return results
    except sqlite3.Error as e:
        print(f"数据库查询错误: {e}")
        return []


if __name__ == '__main__':
    pass